

<div style="padding: 15px;" class="layui-form">
 <div class="layui-form-item">
    <input type="hidden" value={$cate.id} id="cate_id" />
    <label class="layui-form-label">分类名称:</label>
    <div class="layui-inline" style="width:150px;">
     <input type="text" class="layui-input" value={$cate.category_name}  name="category_name" placeholder="分类名称" /> 
    
    </div>
     <div class="layui-inline" style="color:red;"><label  id="error_info" hidden></label></div>
  </div>

<div class="layui-form-item">
  	<label class="layui-form-label">父类:</label>
  <div class="layui-inline" style="width:150px;">
    <select name="category_name">
    	<option value="0">总类</option>
    	{:resolveTree($CateGory,$cate.parent_id)}
    </select>
  </div>
</div>

<div class="layui-form-item">
<button class="layui-btn layui-btn-sm layui-input-block" id="sub">提交</button>
</div>

</div>

<script>



layui.use('form', function(){
  var form = layui.form;

});
$('input[name="category_name"]').focus(function(){
  $('#error_info').css('display','none');
})

$('#sub').click(function(){
  var category_name = $('input[name="category_name"]').val();
  if( category_name==''){
    $('#error_info').text('分类名称不能为空').css('display','block');
    return;
  }

  var parent_id = $('select[name="category_name"]').val();
  var cate_id = $('#cate_id').val();
  var info = {'id':cate_id,'category_name':category_name,'parent_id':parent_id}

  $.post('/admin/category/edit/'+cate_id,info,function(res){
    console.log(res);

      if(res.length == 0){
      	
        window.location.href = '/admin/category';
      }
      else{
      	console.log('error');
      }
  })
})
</script>